package com.xq.springboot.service.impl;

import org.apache.shiro.crypto.hash.Md5Hash;
import org.apache.shiro.util.ByteSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.xq.springboot.mapper.UserMapper;
import com.xq.springboot.pojo.User;
import com.xq.springboot.service.UserService;
/**
 * @author xq
 * @date 2021/4/18 21:58
 * @version 1.0
 * @description 用户业务服务层接口实现层
 */
@Service
public class UserServiceImpl implements UserService{

    @Autowired
    private UserMapper userMapper;

    @Override
    public int insert(User record) {
        // 组合盐（用户名和用户地址）
        String salt = record.getUserName() + record.getAddress();
        // 设置加密密码，Md5Hash类：参数1是默认密码，参数2：加密的盐，参数3：加密散列次数，最终组成的密码加密，参数1为登录的密码
        record.setUserPassword(new Md5Hash(record.getUserPassword(),salt,2).toString());
        return userMapper.insert(record);
    }

    @Override
    public User getUserByUserName(String userName) {
        return this.userMapper.getUserByUserName(userName);
    }

}
